<template>
    <el-container>
        <el-main class="wrapper">
            <v-breadcrumb v-bind:breadcumb="breadcumb"></v-breadcrumb>
            <section class="panel" :style="{'min-height': mainHeight+'px'}">
                <div class="panel-body">
                    <div class="btn-group" style="margin-bottom: 15px">
                        <el-button @click="list" type="primary" icon="fa fa-refresh"
                                   size="small"> 刷新
                        </el-button>
                    </div>
                    <el-table v-loading="loading"
                              element-loading-text="努力加载中..."
                              element-loading-spinner="el-icon-loading"
                              :data="tableData" :border="true" style="width: 100%">
                        <el-table-column prop="title" label="模板标题" width="250px"></el-table-column>
                        <el-table-column prop="template_id" label="模板ID" width="450px"></el-table-column>
                        <el-table-column prop="number" label="发送条数" width="100px"></el-table-column>
                        <el-table-column prop="success_number" label="成功条数" width="100px"></el-table-column>
                        <el-table-column prop="faild_number" label="失败条数" width="100px"></el-table-column>
                        <el-table-column prop="start_at" label="开始时间">
                            <template slot-scope="scope">{{ scope.row.start_at }}</template>
                            <!--<template slot-scope="scope">{{ scope.row.start_at ? moment(scope.row.start_at).format('YYYY-MM-DD HH:mm') : ''}}</template>-->
                        </el-table-column>
                        <el-table-column prop="end_at" label="结束时间">
                            <template slot-scope="scope">{{ scope.row.start_at }}</template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination">
                        <div class="pagination-total">共 <em>{{pageData.total}}</em> 条记录</div>
                        <el-pagination  v-if="!loading && pageData && pageData.last_page > 1" background layout="prev, pager, next, jumper"
                                        :page-size="pageData.per_page"
                                        :total="pageData.total" :current-page="pageData.current_page"
                                        @current-change="handleCurrentChange">
                        </el-pagination>
                    </div>
                </div>
            </section>
        </el-main>
    </el-container>
</template>
<script>
    import {mapGetters} from 'vuex';
    import vBreadcrumb from '../layout/breadcrumb.vue';
    import {MessageRecord} from '../../utils/axios';

    export default {
        components: {vBreadcrumb},
        data() {
            return {
                breadcumb: [{name: "推送记录"},],
                search: {page: null},//筛选
                tableData: [],//列表数据
                pageData: [],//分页数据
            }
        },
        activated() {
            this.$store.dispatch('setActive', '/record');
            this.list();
        },
        computed: {
            ...mapGetters(['active', 'mainHeight', 'loading']),
        },
        methods: {
            //
            list() {
                this.$store.dispatch('setLoading', true);
                MessageRecord({params: this.search}).then((response) => {
                    if (response.code) {
                        this.$message.error(response.msg);
                    } else {

                        this.$store.dispatch('setLoading', false);
                        this.tableData = response.data.data;
                        this.pageData = response.data;
                    }
                    console.info(response)
                })
            },
            //分页
            handleCurrentChange(val) {
                this.search.page = val;
                this.list();
            },
        },
    }
</script>
